/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * author Svetlana Shikhutskaya
 */



$(function(){
    $(document).on('submit', '.find-order',function(e){
        e.preventDefault();
        var number=document.getElementById("tr-number").value;
        if(number!=""){
            document.getElementById("warningFind").innerHTML='';
            $.post('FindOrder',{
                number:number
            },function(result){
                if(result=="found order"){
                    window.location.href="order-view.jsp";
                } else if(result=="found registered order"){
                    document.getElementById("warningFind").innerHTML="Register for view this order";
                } else {
                    document.getElementById("warningFind").innerHTML="Such order doesn't exist";
                }
            })
        }
        else{
            document.getElementById("warningFind").innerHTML="Field shouldn't be empty";
        }
    })
})

function validateTrackingNumber(){
    var tr_number=document.getElementById('tr-number').value;
    var regex=new RegExp("^[0-9]+$");
    var result= regex.test(tr_number);
    if(tr_number.length>0){
        if(result){
            document.getElementById("go-order").disabled=false;
            document.getElementById("warningFind").innerHTML='';
        } else{
            document.getElementById("go-order").disabled=true;
            document.getElementById("warningFind").innerHTML='Enter only numbers';
        }
    }
    else{
        document.getElementById("go-order").disabled=true;
        document.getElementById("warningFind").innerHTML='';
    }
}